package com.yuyu.commons.toolKit;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Objects;

/**
 * @author
 * @version 1.0
 * @description: 时间工具类
 * @date 2022/8/15 9:57
 */
public class DateUtils {

    /**
     * 获取当天凌晨时间戳
     * @return Long
     */
    public static Long getZeroTime(){
      return getStampByLocalDateTime(LocalDateTime.now().with(LocalDateTime.MIN));
    }

   public static LocalDateTime getZeroTimeDate(){
        return LocalDateTime.now().with(LocalDateTime.MIN);
   }

    /**
     *  获取当前时间戳
     * @return
     */
    public static Long getNow(){
        return getStampByLocalDateTime(LocalDateTime.now());
    }

    /**
     * 时间戳转换LocalDateTime
     * @param stamp
     * @return
     */
    public static LocalDateTime getLocalDateTimeByStamp(Long stamp){
     return  LocalDateTime.ofEpochSecond(stamp/1000,0, ZoneOffset.ofHours(8));
    }

    /**
     * LocalDateTime转时间戳
     * @param localDateTime
     * @return
     */
    public static Long getStampByLocalDateTime(LocalDateTime localDateTime){
      return   localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
    }

    /**
     *  判断是否在两个时间之间(时间戳)
     * @param start
     * @param end
     * @return
     */
    public static Boolean betweenIn(Long start,Long end,Long targetTime){
        if (Objects.nonNull(start) && Objects.nonNull(end) && Objects.nonNull(targetTime)){
            return targetTime >= start && targetTime <= end;
        }
        return false;
    }
}
